import json
from unit.models.prefixModel import *
from unit.serializers.prefix.prefixInfoSerializer import PrefixLogSereializer
from unit.utils.unitUtils import unit_log


def init_prefix(file_name):
    tmp_dict1 = {}
    prefix1 = UnitPrefix(prefix_name= "ttaa3",base=99,power=4,prefix_id="P_99_4")
    tmp_dict1["P_99_4"] = prefix1
    prefix2 = UnitPrefix(prefix_name= "ttaa4",base=99,power=5,prefix_id="P_99_5")
    tmp_dict1["P_99_5"] = prefix2
    list1 = []
    list1.append(prefix1)
    list1.append(prefix2)
    unit_prefix_list = UnitPrefix.objects.bulk_create(list1)
    print(unit_prefix_list)
    print("prefix init success")
    print(tmp_dict1["P_99_4"])
    
    
    # with open(file_name, 'r',encoding="utf-8") as f:
    #     data = json.load(f)
    # prefix_unit_list = []
    # for prefix_data in data:
    #     user_name = "admin"
    #     prefix_data["create_person"] = user_name
    #     prefix_data["modify_person"] = user_name
    #     prefix_id = "P"+"_" + \
    #         str(prefix_data["base"])+"_"+str(prefix_data["power"])
    #     prefix_data["prefix_id"] = prefix_id
    #     prefix = UnitPrefix(**prefix_data)
    #     prefix_unit_list.append(prefix)
    # unit_prefix_list = UnitPrefix.objects.bulk_create(prefix_unit_list)
    # unit_log(log_person=user_name, log_type="add", log_objects=[PrefixLogSereializer(
    #     unit_prefix).data for unit_prefix in unit_prefix_list], log_contents=None, log_comment="数据初始化")
